const app = getApp();
const API = require('../../common/constant');
const util = require('../../utils/util');
Page({
  data: {
    money: 120,
    lists: [],
    pageIndex: 1,
    pageSize: 10,
    status: '',
    contentTabItem: ['.content_tab-item-active', '', '']
  },
  goPay() {
    wx.navigateTo({
      url: './pay/index',
    })
  },
  tabChange(e) {
    var btn = e.target.dataset.btn
    var tab = this.data.contentTabItem
    for (let i = 0; i < tab.length; i++) {
      tab[i] = ''
    }
    tab[btn] = '.content_tab-item-active'
    var status =''
    if(btn == 0) {
      status = ''
    } else if (btn == 1){
      status = 'in'
    } else if (btn == 2 ){
      status = 'out'
    }
    this.setData({
      contentTabItem: tab,
      pageIndex: 1,
      moneyType: status,
      lists: []
    })
    this.getInfo()
  },
  getInfo(){
    wx.showLoading({
      title: '正在加载更多'
    })
    util.httpbody({
      url: API.URL.MONEY.FIND_MONEY_INFO,
      data: {
        pageIndex: this.data.pageIndex,
        pageSize: this.data.pageSize,
        moneyType: this.data.moneyType
      },
      success: res => {
        console.log('res', res.data.bussData.userMoney)
        wx.hideLoading();
        this.setData({
          userMoney: res.data.bussData.userMoney,
          lists: this.data.lists.concat(res.data.bussData.userMoneyList.bussData),
          pageIndex: this.data.pageIndex + 1
        })
      },
      fail: err => {
        wx.hideLoading();
        console.log('err', err)
      }
    })
  },
  onLoad(){
    this.getInfo()
  },
  onReachBottom() {
    this.getInfo()
  }
})
